cmake_minimum_required(VERSION 3.5.0)

project(boost_asio_demo)

option(ENABLE_SSL "Enable SSL/HTTPS?" ON)

set(CMAKE_CXX_STANDARD 11)
set(CAMKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

#添加pthread
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
####target_link_libraries(promise Threads::Threads)

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)

find_package(Boost REQUIRED COMPONENTS system date_time thread)
if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
    link_directories(${Boost_LIBRARY_DIRS})
endif()

if(ENABLE_SSL)
    find_package(OpenSSL)
    if(OPENSSL_FOUND)
        include_directories(${OPENSSL_INCLUDE_DIR})
        message(STATUS "OpenSSL libs: " ${OPENSSL_LIBRARIES})
    endif()
endif()

set(LIBS ${Boost_LIBRARIES} "${CMAKE_THREAD_LIBS_INIT}")

if(ENABLE_SSL)
    set(LIBS ${LIBS} ${OPENSSL_LIBRARIES})
endif()

set(TARGETS
    hello_asio
    timer1_sync
    timer2_async
    timer4_multi
    timer5_thread
    echo_server_sync
    echo_client_sync
    echo_server_async
    echo_ssl_server
    echo_ssl_client
    ssl_http_client_async
    )

foreach(name ${TARGETS})
    add_executable(${name} ${name}.cpp)
    target_link_libraries(${name} ${LIBS})
endforeach()

